package org.lanplay.server.dao;

import java.util.List;

import javax.persistence.EntityManager;

import org.lanplay.server.model.MatchRequest;

import com.google.inject.Inject;
import com.google.inject.Provider;

public class GameReferenceDao {
	@Inject
	private Provider<EntityManager> emp;

	@SuppressWarnings("unchecked")
	public List<MatchRequest> getMatchRequestsForUserId(Long userId) {
		return emp
				.get()
				.createQuery(
						"SELECT r from MatchRequest r where r.user.id=:user")
				.setParameter("user", userId).getResultList();
	}

	public void save(MatchRequest matchRequest) {
		emp.get().persist(matchRequest);
	}

	public void delete(MatchRequest matchRequest) {
		emp.get().remove(matchRequest);
	}

}
